import React from 'react';
const loadjs = window.loadjs;
import isEqual from "lodash/isEqual";

export default class WfCenterLogList extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            hasLoad: false,
            store: null,
            visiable: false,
            requestid: '',
            f_weaver_belongto_userid:'',
            f_weaver_belongto_usertype:''
        };
        this.signviewPoistion = this.signviewPoistion.bind(this);
        this.onCancel = this.onCancel.bind(this);
    }

    componentWillReceiveProps(nextProps) {
        const {eid, tabid, refresh} = this.props;
        if (nextProps.tabid !== tabid || refresh !== nextProps.refresh) {
        }
    }

    shouldComponentUpdate(nextProps, nextState) {
        return !isEqual(this.state, nextState) || !isEqual(this.props, nextProps)
    }

    signviewPoistion(value,value1,value2) {
        if(value) {
            const init = () => {
                const {requestid = -1, visible = false} = this.props;
                const {WfCenterLogListStore} = window.weaWorkflowPublic;
                const store = new WfCenterLogListStore();
                this.setState({hasLoad: true, store: store});
            }
            loadjs.isDefined('workflowPublic') ? loadjs.ready('workflowPublic', init) : loadjs([
                "/spa/workflow/static4public/index.js",
                "/spa/workflow/static4public/index.css"
            ], 'workflowPublic', init);
        }
        this.setState({
            visiable: true,
            requestid: value,
            f_weaver_belongto_userid:value1,
            f_weaver_belongto_usertype:value2,
        });
    }
    onCancel(v){
        this.setState({visiable: false, requestid: -1});
        window.element_workflow_reLoad();
    }
    render() {
        const {hasLoad, store, visiable, requestid,f_weaver_belongto_userid,f_weaver_belongto_usertype} = this.state;
        const {more} = this.props;
        if (hasLoad) {
            const {WfCenterLogList} = window.weaWorkflowPublic;
            if (visiable && requestid > -1) {
                if(more && JSON.parse(more).viewType != "6"){
                    store.init({requestid,f_weaver_belongto_userid,f_weaver_belongto_usertype}, visiable);
                }else{
                    store.init({requestid,f_weaver_belongto_userid,f_weaver_belongto_usertype, urger: 1}, visiable);
                }
            }
            return (
                <WfCenterLogList ecId={`${this && this.props && this.props.ecId || ''}_WfCenterLogList@fcoz33`} onCancel={(v) => this.onCancel(v)}
                                 wfCenterLogListStore={store}/>
            )
        } else {
            return (<div></div>);
        }
    }
}